package com.zz.yt.lib.bluetooth.delegate.print.zk.modle;


import androidx.annotation.NonNull;

import com.whf.android.jar.util.log.LatteLogger;
import com.zz.yt.lib.bluetooth.bt.printer.zpBluetoothPrinter;



/**
 * 打印内容
 */
public class PrintZkManager {

    private final static int height = 60;

    /*** 默认每行的高度*/
    protected final int yAxis;

    /*** 打印对象*/
    protected final zpBluetoothPrinter zpSDK;

    /*** y轴 */
    protected int yText = 6;


    @NonNull
    public static PrintZkManager create(zpBluetoothPrinter zpSDK) {
        return new PrintZkManager(zpSDK, 45);
    }

    @NonNull
    public static PrintZkManager create(zpBluetoothPrinter zpSDK, int yAxis) {
        return new PrintZkManager(zpSDK, yAxis);
    }


    protected PrintZkManager(zpBluetoothPrinter zpSDK, int yAxis) {
        this.yAxis = yAxis;
        this.zpSDK = zpSDK;
    }


    /**
     * 标签打印测试页
     */
    public void startLabel() {
        yText = 6;
        // 打印标题
        setText(220, "测试收费清单");
        //打印内容
        aline("单号", "211223001", "业主", "徐秀峰");
        aline("日期", "2021-12-23", "时间", "11:12:40");
        aline("收费", "测试用户", "房号", "1-1101");

        //drawLine();

        alineCharge(true);
        alineCharge(false, "物业费22年1月", "93.7", "平方", "1.2", "112.44");
        alineCharge(false, "物业费22年2月", "93.7", "平方", "1.2", "543.21");
        alineCharge(false, "物业费22年3月", "93.7", "平方", "1.2", "123.45");
        alineCharge(false, "车位费22年1月", "1", "个", "30", "30");
        alineCharge(false, "车位费22年2月", "1", "个", "30", "30");
        alineCharge(false, "车位费22年3月", "1", "个", "30", "30");

        //drawLine();

        endPrint(" 506.3", " 500.0", "测试物业公司", "测试小区", "监督电话: 023-4008008820");

    }


    /**
     * 每一个输入标签
     *
     * @param x:
     * @param text:绘制简体中文
     */
    protected void setText(int x, @NonNull String text) {
        int width = 40 + text.length() * 24 * 4;
        zpSDK.drawText(x, yText, width, height, text);
    }


    /**
     * 标签打印虚线
     */
    protected void drawLine() {
        line();
        zpSDK.drawLine(2, 20, yText, 540, yText, false);
    }


    /**
     * 基本信息
     *
     * @param paramString：
     */
    protected void aline(@NonNull String... paramString) {
        line();
        setText(20, paramString[0] + ": " + paramString[1]);
        setText(300, paramString[2] + ": " + paramString[3]);
    }


    /**
     * 收费信息
     *
     * @param is：
     * @param paramString：
     */
    protected void alineCharge(boolean is, @NonNull String... paramString) {
        line();
        if (!is && paramString.length < 4) {
            LatteLogger.e("收费信息有误");
            return;
        }
        setText(20, is ? "项目" : paramString[0]);
        setText(230, is ? "数量" : paramString[1]);
        setText(320, is ? "单位" : paramString[2]);
        setText(400, is ? "单价" : paramString[3]);
        setText(480, is ? "金额" : paramString[4]);

    }

    /**
     * @param paramString：信息尾页
     */
    protected void endPrint(@NonNull String... paramString) {
        if (paramString.length > 4) {
            line();
            setText(20, "应付金额 :");
            setText(380, paramString[0]);

            line();
            setText(20, "实付金额 :");
            setText(380, paramString[1]);


            yText += 60;
            setText(150, "** " + paramString[2] + " **");
            yText += 60;
            setText(180, "** " + paramString[3] + " **");
            yText += 60;
            setText(50, "[举报电话:" + paramString[4] + "]");
        }
    }

    private void line() {
        yText += yAxis;
    }

}
